#ifndef __ES8266_MQTT_H
#define __ES8266_MQTT_H

#include <stm32f4xx.h>


//此处是阿里云服务器的公共实例登陆配置
#define MQTT_BROKERADDRESS 		"hvz7zihjC3V.iot-as-mqtt.cn-shanghai.aliyuncs.com"
#define MQTT_CLIENTID 			"0001|securemode=3,signmethod=hmacsha1|"
#define MQTT_USARNAME 			"smart-device&hvz7zihjC3V"
#define MQTT_PASSWD 			"844C93A8130602A332123C8D8F7D4615149BCBAC"
#define	MQTT_PUBLISH_TOPIC 		"/sys/hvz7zihjC3V/smart-device/thing/event/property/post"
#define MQTT_SUBSCRIBE_TOPIC 	"/sys/hvz7zihjC3V/smart-device/thing/service/property/set"


#define BYTE0(dwTemp)       (*( char *)(&dwTemp))
#define BYTE1(dwTemp)       (*((char *)(&dwTemp) + 1))
#define BYTE2(dwTemp)       (*((char *)(&dwTemp) + 2))
#define BYTE3(dwTemp)       (*((char *)(&dwTemp) + 3))


/**
 @brief MQTT发送数据
 @retval 成功为0,错误非0
*/
void mqtt_send_bytes(uint8_t *buf,uint32_t len);


/**
 @brief MQTT无条件断开
 @retval 成功为0,错误非0
*/
extern void mqtt_disconnect(void);


/**
 @brief MQTT连接服务器
 @retval 成功正确为0,错误非0
*/
extern int32_t mqtt_connect(char *client_id,char *user_name,char *password);


/**
 @brief MQTT订阅/取消订阅数据打包函数
 @param topic:   主题
 @param qos:     消息等级
 @param whether: 订阅/取消订阅请求包
 @retval 成功为0,错误非0
*/
extern int32_t mqtt_subscribe_topic(char *topic, uint8_t qos, uint8_t whether);


/**
 @brief MQTT消息发布
 @param topic:   主题
 @param message: 消息
 @param qos:     消息等级
 @retval 成功为0,错误非0
*/
extern uint32_t mqtt_publish_data(char *topic, char *message, uint8_t qos);


/**
 @brief MQTT发送心跳包
 @retval 获取为0,错误非0
*/
extern int32_t mqtt_send_heart(void);


/**
 @brief 设备状态上报测试
*/
extern void mqtt_report_devices_status_test(float temperature, float humidity,
									uint8_t switch_led_1, uint32_t fl1_on_time, uint32_t fl1_off_time);

/**
 @brief 连接阿里云物联网平台初始化
 @retval 获取正确为0,错误非0
*/
extern int32_t esp8266_mqtt_init(void);

#endif
